<template>
	<div class="statistics padding20">
		<el-form inline>
			<el-form-item label="会员名称">
				<el-input type="text" maxlength="100" v-model="search.memberName" clearable @keydown.native.enter="onSearch" placeholder="请输入会员名称" />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" @click="getStatus">搜索</el-button>
			</el-form-item>
		</el-form>

		<el-table :data="examPeopleList" border>
			<el-table-column prop="memberName" label="人员"></el-table-column>
			<el-table-column prop="quizTime" label="答题时间"></el-table-column>
			<el-table-column prop="highScore" label="最高成绩"></el-table-column>
			<el-table-column prop="examNum" label="考试次数"></el-table-column>
			<el-table-column prop="status" label="状态">
				<template #default="{row: {status}}">
					{{ status == 1 ? "通过" : "未通过" }}
				</template>
			</el-table-column>
			<el-table-column label="查看试卷" fixed="right">
				<template #default="{ row }">
					<vViewOrder :id="row.memberId"></vViewOrder>
				</template>
			</el-table-column>
		</el-table>

		<br />
		<br />

		<FortressPagination :total="total" :current-page="search.current" :page-size="search.size" @refreshData="onCurrentChange"></FortressPagination>
	</div>
</template>

<script>
import request from "@/common/request"
import FortressPagination from "@/components/fortress-pagination.vue"
import vViewOrder from "./studyexam-view-order.vue"

export default {
	name: "Statistics",
	data() {
		return {
			examPeopleList: [],
			total: 0,
			search: {
				current: 1,
				size: 10,
				memberName: "",
				status: "",
			},
		}
	},
	created() {
		this.total = 0
		this.examPeopleList = []
		this.search.current = 1
		this.search.size = 10
		this.search.memberName = ""
		this.search.status = ""

		this.getStatus()
	},
	methods: {
		async getStatus() {
			try {
				const { code, data, msg } = await request("get", "/study/exam/studyExamStatistics/page", {
					...this.search,
					examId: this.$route.query.id,
				})
				if (code != 0) {
					throw new Error(msg)
				}
				this.examPeopleList = data.records
				this.total = data.total
			} catch (error) {
				this.$message.error(error.message)
			}
		},
		onCurrentChange({ current, size }) {
			this.search.current = current
			this.search.size = size
			this.getStatus()
		},
		onSearch() {
			this.examPeopleList = []
			this.total = 0
			this.onCurrentChange({ current: 1, size: this.search.size })
		},
	},
	components: {
		FortressPagination,
		vViewOrder,
	},
}
</script>

<style lang="scss" scoped>
.Statistics {
	display: inline-block;
}
</style>
